package com.atguigu.spzx.manage.controller;

import com.atguigu.spzx.manage.service.EventService;
import com.atguigu.spzx.model.dto.system.EventDto;
import com.atguigu.spzx.model.entity.system.Event;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/admin/system/event")
@Slf4j
@Tag(name = "活动管理接口")
public class EventController {
    @Autowired
    private EventService eventService;



    @Operation(summary = "活动管理分页查询")
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<Event>> findByPage(EventDto eventDto ,
                                                @PathVariable(value = "pageNum") Integer pageNum ,
                                                @PathVariable(value = "pageSize") Integer pageSize) {
        log.info("用户查询内容:{},页码:{},页数:{}",eventDto,pageNum,pageSize);
        PageInfo<Event> pageInfo = eventService.findByPage(eventDto , pageNum , pageSize) ;
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }


    @Operation(summary = "添加活动")
    @PostMapping(value = "/saveEvent")
    public Result saveSysUser(@RequestBody Event event) {
        log.info("添加的活动:{}",event);
        eventService.saveEvent(event) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


    @Operation(summary = "更新活动")
    @PutMapping(value = "/updateEvent")
    public Result updateSysUser(@RequestBody Event event) {
        log.info("修改用户内容:{}",event);
        eventService.updateEvent(event) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "发布活动")
    @PutMapping(value = "/startById/{eventId}")
    public Result startById(@PathVariable(value = "eventId") Long id) {
        eventService.startById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "关闭活动")
    @PutMapping(value = "/endById/{eventId}")
    public Result endById(@PathVariable(value = "eventId") Long id) {
        eventService.endById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


    @Operation(summary = "删除活动")
    @DeleteMapping(value = "/deleteById/{eventId}")
    public Result deleteById(@PathVariable(value = "eventId") Long id) {
        eventService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


}
